/**
 * @param {number} target
 * @param {number[]} nums
 * @return {number}
 */

const minSubArrayLen = (target, nums) => {
  const len = nums.length
  let slow = 0, fast = 0, sum = 0, res = Infinity

  while (fast < len) {
    sum += nums[fast]
    console.log(slow, fast, sum, '+++++++');
    if (sum >= target) {
      res = Math.min(res, (fast - slow))
      slow = fast + 1
      // fast = slow - 1
      sum = 0
    }
    fast++
  }

  return res === Infinity ? 0 : res + 1
}

console.log(minSubArrayLen(7, [2, 3, 1, 2, 4, 3]))